#include "log.h"
#include "http/http_server.h"

static johnsonli::Logger::ptr g_logger = LOG_ROOT();

void run()
{
    johnsonli::http::HttpServer::ptr server(new johnsonli::http::HttpServer(true));
    johnsonli::Address::ptr addr = johnsonli::Address::LookupAnyIPAddress("0.0.0.0:8020");
    while(!server->bind(addr)) {
        sleep(2);
    }

    auto dsp = server->getServletDispatch();
    dsp->addServlet("/sylar/xx", [](johnsonli::http::HttpRequest::ptr req
                                    , johnsonli::http::HttpResponse::ptr rsp
                                    , johnsonli::http::HttpSession::ptr session){
        rsp->setBody(req->toString());
        return 0;                           
    });

    dsp->addGlobServlet("/sylar/*", [](johnsonli::http::HttpRequest::ptr req
                                    , johnsonli::http::HttpResponse::ptr rsp
                                    , johnsonli::http::HttpSession::ptr session){
        rsp->setBody("Glob:\r\n" + req->toString());
        return 0;                           
    });

    server->start();
}

int main()
{
    johnsonli::IOManager iom(1);
    iom.schedule(run);

    return 0;
}